#ifndef CUSTOMOBJECT_H
#define CUSTOMOBJECT_H


#include "Framework/Prerequisites.h"
#include "Geometry/Object.h"
#include "Graphics/IRenderOperation.h"
#include "IO/ResourceGroupManager.h"
#include "Math/Vector2.h"
#include "Math/Vector3.h"
#include "Math/Vector4.h"
#include "Graphics/Colour.h"


namespace tyro
{
	namespace Geometry
	{
		class CustomObject : public Object
		{
		public:

			CustomObject(const String& name, Graphics::IDeviceBufferManager* mgr);

			virtual void BeginBuild(const String& materialName, Graphics::MaterialManager* matMgr, RenderType renderType = RT_TRIANGLE_LIST, const String& groupName = IO::ResourceGroupManager::DEFAULT_GROUP_NAME );

			virtual void AddVertex(FLOAT_32 x, FLOAT_32 y, FLOAT_32 z);
			virtual void AddVertex(const Math::Vector3f& vec);
			virtual void AddNormal(FLOAT_32 x, FLOAT_32 y, FLOAT_32 z);
			virtual void AddNormal(const Math::Vector3f& vec);
			virtual void AddTextureCoord(FLOAT_32 u, FLOAT_32 v);
			virtual void AddTriangle(UINT_32 x, UINT_32 y, UINT_32 z);
			CustomObjectSection* GetSection(UINT_32 index) const;
			virtual void EndBuild();
			virtual void Index( UINT_32 index );
			void ResizeIndexBuffer( size_t indexCount );
			virtual void CopyVertexToBuffer( void );
			virtual void ResizeVertexBuffer( size_t vertexCount );

			void UpdateRenderQueue(Scene::IRenderQueue* renderQueue);
		protected:

			struct TempVertexData
			{
				Math::Vector3f vertex;
				Math::Vector3f normal;
				Math::Vector3f tangent;
				Math::Vector4f texCoord[MAX_TEXTURE_COORD_SETS];
				USHORT_16	textCoordDims[MAX_TEXTURE_COORD_SETS];
				Graphics::Colour	colour;

			};

			Graphics::IDeviceBufferManager* bufferManager;
			TempVertexData			tempVertex;
			CustomObjectSectionList	sectionList;
			CustomObjectSection*	activeSection;
			
			bool					firstVertex;
			bool					vertexPending;
			bool					currentUpdating;
			bool					indexed;

			char*					tempVertexBuffer;
			size_t					tempVertexSize;
			UINT_32*				tempIndexBuffer;
			size_t					tempIndexSize;

			size_t					declSize;

			size_t					estVertexCount;
			size_t					estIndexCount;

			USHORT_16				texCoordIndex;
			


		private:
		};

		

		

	}
}
#endif